home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WINER.ZIP / MESSAGE$.ASM < prev    next >
Assembly Source File  |  1992-05-13  |  3KB  |  105 lines

  1. ;MESSAGE$.ASM, returns a specified string as a function
  2.  
  3. ;Copyright (c) 1991 Ethan Winer
  4.  
  5. ;Syntax:
  6. ;
  7. ;   DECLARE FUNCTION Message$(BYVAL MsgNumber%)
  8. ;   PRINT Message$(AnyInt%)
  9.  
  10.  
  11. .Model Medium, Basic
  12.   Extrn B$ASSN:Proc         ;BASIC's assignment routine
  13.  
  14. .Data
  15.   Descriptor DD 0           ;the output string descriptor
  16.   Null$      DD 0           ;use this to return a null
  17.   
  18. .Code
  19.  
  20. Message Proc Uses SI, MsgNumber:Word
  21.  
  22.   Mov  SI,Offset Messages   ;point to start of messages
  23.   Xor  AX,AX                ;assume an invalid value
  24.   
  25.   Mov  CX,MsgNumber         ;load the message number
  26.   Cmp  CX,NumMsg            ;does this message exist?
  27.   Ja   Null                 ;no, return a null string
  28.   Jcxz Null                 ;ditto if they pass a zero
  29.  
  30. Do:                         ;walk through the messages
  31.   Lods Word Ptr CS:0        ;load and skip over this
  32.                             ;  message length
  33.   Dec  CX                   ;show that we read another
  34.   Jz   Done                 ;this is the one we want
  35.   
  36.   Add  SI,AX                ;skip over the message text
  37.   Jmp  Short Do             ;continue until we're there
  38.  
  39. Done:
  40.   Or   AX,AX                ;are we returning a null?
  41.   Jz   Null                 ;yes, handle that differently
  42.   Push CS                   ;no, pass the source segment
  43.   
  44. Done2:
  45.   Push SI                   ;and the source address
  46.   Push AX                   ;and the source length
  47.  
  48.   Push DS                   ;pass the destination segment
  49.   Mov  AX,Offset Descriptor ;and the destination address
  50.   Push AX
  51.   Xor  AX,AX                ;0 means assign a descriptor
  52.   Push AX                   ;pass that as well
  53.   
  54.   Call B$ASSN               ;let B$ASSN do the dirty work
  55.   Mov  AX,Offset Descriptor ;show where the output is
  56.   Ret                       ;return to BASIC
  57.  
  58. Null:
  59.   Push DS                   ;pass the address of Null$
  60.   Mov  SI,Offset Null$
  61.   Jmp  Short Done2
  62.  
  63. Message Endp
  64.  
  65.  
  66. ;----- DefMsg macro that defines messages
  67. ;
  68. ;Usage:
  69. ;  DefMsg "This is the message text."
  70. ;
  71. ;  You may also pass a mix of character values and quoted text by enclosing
  72. ;  the entire string in angled brackets like this:
  73. ;
  74. ;     DefMsg <34, "This is quoted text", 34>
  75. ;
  76. ;  Using DefMsg with no arguments lets you have a null message, perhaps
  77. ;  as a placeholder for an unused message number.
  78. ;
  79. DefMsg Macro Message
  80.   Local MsgStart, MsgEnd    ;; local address labels
  81.   NumMsg = NumMsg + 1       ;; show we made another one
  82.   IFB <Message>             ;; if no text is defined
  83.     DW 0                    ;; just create an empty zero
  84.   ELSE                      ;; else create the message
  85.     DW MsgEnd - MsgStart    ;; first write the length
  86.     MsgStart:               ;; identify starting address
  87.       DB Message            ;; define the message text
  88.     MsgEnd Label Byte       ;; this marks the end
  89.   ENDIF
  90. Endm
  91.  
  92.  
  93. Messages Label Byte         ;the messages begin here
  94. NumMsg = 0                  ;tracks number of messages
  95.  
  96. DefMsg "Sunday"
  97. DefMsg "Monday"
  98. DefMsg "Tuesday"
  99. DefMsg "Wednesday"
  100. DefMsg "Thursday"
  101. DefMsg "Friday"
  102. DefMsg "Saturday"
  103.  
  104. End
  105.